package com.tech.connect.huanzhewan;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.ksy.common.utils.BaseAdapter;
import com.ksy.common.utils.BaseHolder;
import com.tech.connect.R;
import com.tech.connect.activity.BaseActivity;
import com.tech.connect.model.OptChoose;

import java.util.ArrayList;
import java.util.List;

public class HuanZheWanOptionsChooseActivity extends BaseActivity {

    private RecyclerView recycler1;
    private RecyclerView recycler2;
    private RecyclerView recycler3;
    private RecyclerView recycler4;
    private List<OptChoose> all1 = new ArrayList<>();
    private List<OptChoose> all2 = new ArrayList<>();
    private List<OptChoose> all3 = new ArrayList<>();
    private List<OptChoose> all4 = new ArrayList<>();
    private BaseAdapter<OptChoose, BaseHolder> adapter1;
    private BaseAdapter<OptChoose, BaseHolder> adapter2;
    private BaseAdapter<OptChoose, BaseHolder> adapter3;
    private BaseAdapter<OptChoose, BaseHolder> adapter4;
    private TextView tvAll;
    private TextView tvOnLine;
    private OptChoose select1 =null;
    private OptChoose select2 = null;
    private OptChoose select3 = null;
    private OptChoose select4 =null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getHeadBar().setTitle("筛选条件");
        setContentView(R.layout.activity_option_choose);
        initView();
        loadData();
    }

    private void loadData() {
//        FWHttp.fuwuChooseList(new BaseEntityOb<Map<String, List<OptChoose>>>() {
//            @Override
//            public void onDataDeal(boolean isSuccess, Map<String, List<OptChoose>> data, String msg) {
//                List<OptChoose> validType = null;
//                List<OptChoose> distance = null;
//                List<OptChoose> gender = null;
//                List<OptChoose> age = null;
//                if (isSuccess && data != null) {
//                    validType = data.get("validType");
//                    distance = data.get("distance");
//                    gender = data.get("gender");
//                    age = data.get("age");
//                }
//                initAdapter1(gender);
//                initAdapter2(age);
//                initAdapter3(distance);
//                initAdapter4(validType);
//            }
//        });


    }

    private void initAdapter1(List<OptChoose> list) {
        all1.clear();
        if (list != null) {
            all1.addAll(list);
        }
        if (adapter1 == null) {
            adapter1 = new BaseAdapter<OptChoose, BaseHolder>(R.layout.item_layout_text, all1) {
                @Override
                protected void convert(BaseHolder helper, int position) {
                    OptChoose s = all1.get(position);
                    TextView view = helper.getView(R.id.tv);
                    view.setText(s.description);
                    if (select1.equals(s)) {
                        view.setSelected(true);
                        view.setBackgroundResource(R.drawable.common_shape_corner5_stroke_yellow);
                    } else {
                        view.setSelected(false);
                        view.setBackgroundResource(R.drawable.common_shape_corner5_stroke_gray);
                    }
                }
            };
            adapter1.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    select1 = all1.get(position);
                    adapter1.notifyDataSetChanged();
                }
            });
            recycler1.setAdapter(adapter1);
        }
        adapter1.notifyDataSetChanged();
    }

    private void initAdapter2(List<OptChoose> list) {
        all2.clear();
        if (list != null) {
            all2.addAll(list);
        }
        if (adapter2 == null) {
            adapter2 = new BaseAdapter<OptChoose, BaseHolder>(R.layout.item_layout_text, all2) {
                @Override
                protected void convert(BaseHolder helper, int position) {
                    OptChoose s = all2.get(position);
                    TextView view = helper.getView(R.id.tv);
                    view.setText(s.description);
                    if (select2.equals(s)) {
                        view.setSelected(true);
                        view.setBackgroundResource(R.drawable.common_shape_corner5_stroke_yellow);
                    } else {
                        view.setSelected(false);
                        view.setBackgroundResource(R.drawable.common_shape_corner5_stroke_gray);
                    }
                }
            };
            adapter2.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    select2 = all2.get(position);
                    adapter2.notifyDataSetChanged();
                }
            });
            recycler2.setAdapter(adapter2);
        }
        adapter2.notifyDataSetChanged();
    }

    private void initAdapter3(List<OptChoose> list) {
        all3.clear();
        if (list != null) {
            all3.addAll(list);
        }
        if (adapter3 == null) {
            adapter3 = new BaseAdapter<OptChoose, BaseHolder>(R.layout.item_layout_text, all3) {
                @Override
                protected void convert(BaseHolder helper, int position) {
                    OptChoose s = all3.get(position);
                    TextView view = helper.getView(R.id.tv);
                    view.setText(s.description);
                    if (select3.equals(s)) {
                        view.setSelected(true);
                        view.setBackgroundResource(R.drawable.common_shape_corner5_stroke_yellow);
                    } else {
                        view.setSelected(false);
                        view.setBackgroundResource(R.drawable.common_shape_corner5_stroke_gray);
                    }
                }
            };
            adapter3.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    select3 = all3.get(position);
                    adapter3.notifyDataSetChanged();
                }
            });
            recycler3.setAdapter(adapter3);
        }
        adapter3.notifyDataSetChanged();
    }

    private void initAdapter4(List<OptChoose> list) {
        all4.clear();
        if (list != null) {
            all4.addAll(list);
        }
        if (adapter4 == null) {
            adapter4 = new BaseAdapter<OptChoose, BaseHolder>(R.layout.item_layout_text, all4) {
                @Override
                protected void convert(BaseHolder helper, int position) {
                    OptChoose s = all4.get(position);
                    TextView view = helper.getView(R.id.tv);
                    view.setText(s.description);
                    if (select4.equals(s)) {
                        view.setSelected(true);
                        view.setBackgroundResource(R.drawable.common_shape_corner5_stroke_yellow);
                    } else {
                        view.setSelected(false);
                        view.setBackgroundResource(R.drawable.common_shape_corner5_stroke_gray);
                    }
                }
            };
            adapter4.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    select4 = all4.get(position);
                    adapter4.notifyDataSetChanged();
                }
            });
            recycler4.setAdapter(adapter4);
        }
        adapter4.notifyDataSetChanged();
    }


    private void initView() {
//        TextView tvTag1 = findViewById(R.id.tvTag1);
//        TextView tvTag2 = findViewById(R.id.tvTag2);
//        TextView tvTag3 = findViewById(R.id.tvTag3);
//        TextView tvTag4 = findViewById(R.id.tvTag4);
//        tvTag1.setText("性别");
//        tvTag2.setText("年龄");
//        tvTag3.setText("距离");
//        tvTag4.setText("认证");
//        recycler1 = findViewById(R.id.recycler1);
//        recycler2 = findViewById(R.id.recycler2);
//        recycler3 = findViewById(R.id.recycler3);
//        recycler4 = findViewById(R.id.recycler4);
//        tvAll = findViewById(R.id.tvAll);
//        tvAll.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                tvAll.setSelected(true);
//                tvOnLine.setSelected(false);
//            }
//        });
//        tvAll.setSelected(false);
//        tvOnLine = findViewById(R.id.tvOnLine);
//        tvOnLine.setSelected(true);
//        tvOnLine.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                tvAll.setSelected(false);
//                tvOnLine.setSelected(true);
//            }
//        });
//        findViewById(R.id.btReset).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                select1 = null;
//                select2 = null;
//                select3 = null;
//                select4 = null;
//                adapter1.notifyDataSetChanged();
//                adapter2.notifyDataSetChanged();
//                adapter3.notifyDataSetChanged();
//                adapter4.notifyDataSetChanged();
//                tvAll.performClick();
//            }
//        });
//        findViewById(R.id.btEnter).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//            }
//        });
//        GridOffsetsItemDecoration offsetsItemDecoration = new GridOffsetsItemDecoration(
//                GridOffsetsItemDecoration.GRID_OFFSETS_VERTICAL);
//        offsetsItemDecoration.setVerticalItemOffsets(AndroidUtil.dip2px(8));
//        offsetsItemDecoration.setHorizontalItemOffsets(AndroidUtil.dip2px(8));
//        recycler1.addItemDecoration(offsetsItemDecoration);
//        recycler2.addItemDecoration(offsetsItemDecoration);
//        recycler3.addItemDecoration(offsetsItemDecoration);
//        recycler4.addItemDecoration(offsetsItemDecoration);
//        recycler1.setLayoutManager(new GridLayoutManager(activity, 3));
//        recycler2.setLayoutManager(new GridLayoutManager(activity, 3));
//        recycler3.setLayoutManager(new GridLayoutManager(activity, 3));
//        recycler4.setLayoutManager(new GridLayoutManager(activity, 3));
    }
}
